<template>
  <div class="transfer">
    <form class="form-input">
      <div style="border-bottom: 1px solid #eeeeee;">
        <x-input v-model="useID"  :placeholder="$t('accountID')" style="padding-top: 0">
        </x-input>
      </div>
      <div style="border-bottom: 1px solid #eeeeee">
        <x-input    v-model="phone" :placeholder="$t('phone')">
        </x-input>
      </div>
      <div style="border-bottom: 1px solid #eeeeee">
        <x-input    v-model="num" :placeholder="$t('trade num')">
        </x-input>
      </div>
      <div style="border-bottom: 1px solid #eeeeee">
        <x-input  type="password"  v-model="pwd" :placeholder="$t('pwd')">
        </x-input>
      </div>
    </form>
    <x-button :gradients="buttonColor"  @click.native="transaction">{{$t('confirm')}}</x-button>


    <div v-transfer-dom>
      <confirm v-model="show"
               :title="$t('info')"
               @on-cancel="onCancel"
               @on-confirm="onConfirm">
        <p style="text-align:center; color: #999">{{$t('pay now')}}</p>
      </confirm>
    </div>
  </div>

</template>

<i18n>
  accountID:
    en: Account Id
    zh-CN: 请输入ID账号
  phone:
    en: Phone
    zh-CN: 请输入手机号
  trade num:
    en: Trade Num
    zh-CN: 请输入交易数量
  pay now:
    en: You will pay!
    zh-CN: 确定转账吗?
</i18n>

<script>
import {Confirm, XInput, XButton, TransferDomDirective as TransferDom} from 'vux'
export default {
  directives: {
    TransferDom
  },
  name: 'Transfer',
  components: {
    XInput,
    XButton,
    Confirm
  },
  data () {
    return {
      buttonColor: ['#537fbf', '#537fbf'],
      phone: '',
      pwd: '',
      num: '',
      useID: '',
      show: false
    }
  },
  methods: {
    transaction () {
      if (this.phone === '' || this.pwd === '' || this.num === '' || this.useID === '') {
        this.$vux.toast.text('请填写完整信息', 'middle')
      } else {
        this.show = true
      }
    },
    onConfirm () {
      console.log('on confirm')
      let vue = this
      let url = 'api/deal/transfer'
      vue.post({
        url: url,
        params: {
          token: localStorage.token,
          pay_password: vue.pwd,
          transfer_id: vue.useID,
          transfer_mobile: vue.phone,
          cny: vue.num
        },
        success: function (data) {
          console.log(data)
          if (data.code === 1) {
            vue.$vux.toast.text(data.msg, 'middle')
          } else {
            vue.$vux.toast.text(data.msg, 'middle')
          }
        }
      })
    },
    onCancel () {
    }
  }
}
</script>

<style lang="less">
  .transfer {
    height: 100%;
    background-color: #fff;
    padding: 0.4rem;
    box-sizing: border-box;
    .form-input {
      padding: 15px 0;
      padding-bottom: 1.2rem;
      div {
        .vux-x-input {
          height: 0.5rem;
          padding-left: 0.1rem;
          padding-bottom: 0.1rem;
          padding-top: 0.6rem;
          font-size: 0.26rem;
          input {
            height: 0.5rem;
          }
          input::-webkit-input-placeholder {
            color: #a7a7a7 !important;
            font-size: 0.27rem;
          }
        }
        .iconfont1 {
          border-right: 1px solid #dddddd;
          font-size: 0.33rem;
        }
        .weui-btn:after {
          border: none;
        }
      }
    }
    .weui-dialog .weui-dialog__ft:after{
      border-top: solid 0.1rem #537fbe;
    }
  }
</style>
